package com.firmiana.jt809.entity;

import com.firmiana.jt809.config.GlobalConfig;
import com.firmiana.jt809.util.FunctionUtils;
import lombok.Data;

/**
 *  809消息体
 * @author hucl
 * @date 2020/8/25 11:08
 */
@Data
public class JT809Message {
    // 0x5b开始标志
    private String headFlag;
    // 整个809包的长度 1 + 4 + 4 + 2 + 4 + 3 + 1 + 4 + 2 + 1 + 数据体的长度
    private long msgLength; // 4个字节无符号，只能向高一级的类型转换
    // 4个字节的流水号
    private long msgSN;
    // 2个字节
    private int msgType;
    // 下级平台接入码
    private long msgGNSSCenterID;
    // 版本三个字节
    private byte[] versionFlag;
    // 加密标志 0 不加密 1加密
    private byte encryptFlag;
    // 加密密钥 4个字节 无符号整数
    private long encryptKey;
    // 数据体
    private String messageBody;
    // 2个字节
    private String CRCCode;
    // 0x5d结束标志
    private String endFlag;
    //子类型标识
    private int subType;
    //车牌号
    private String plateNo;
    //车牌颜色
    private int plateColor;

    private int contentLength;
    //消息内容描述
    private String msgDesc;

    private String packetDesc;
    //标示上下行
    private String remark = "";

    public JT809Message(int _msgType) {
        msgType = _msgType;
        headFlag = "5b";
        endFlag = "5d";
        versionFlag = new byte[]{1, 1, 1};
        msgGNSSCenterID = GlobalConfig.parModel.getPlatformCenterId();
    }

    public JT809Message(int _msgType, String body) {
        msgType = _msgType;
        messageBody = body;
        headFlag = "5b";
        endFlag = "5d";
        versionFlag = new byte[]{1, 1, 1};
        msgGNSSCenterID = GlobalConfig.parModel.getPlatformCenterId();
    }

    public JT809Message(int _msgType, int _subType, String body) {
        msgType = _msgType;
        subType = _subType;
        messageBody = body;
        headFlag = "5b";
        endFlag = "5d";
        versionFlag = new byte[]{1, 1, 1};
        msgGNSSCenterID = GlobalConfig.parModel.getPlatformCenterId();
    }

    public String toHexString() {
        return FunctionUtils.getHeaderAndFlag(GlobalConfig.getSN(), messageBody, msgType,
                msgGNSSCenterID, false);
    }


}
